#include <stdio.h>

class Base
{
public:
    Base() = default;
    ~Base() = default;

private:
    int m_a;

public:
    int test_override() { printf("Base::test_override()\n"); };
    int test_override_overload(int a) { printf("Base::test_override_overload(int a)\n"); }; // overload 重载
    int test_not_override() { printf("Base::test_override()\n"); };
    int test_not_override_overload(int a) { printf("Base::test_not_override_overload(int a)\n"); }; // overload 重载
    virtual int test_virtual_override() { printf("Base::test_override()\n"); };
    virtual int test_virtual_override_overload(int a) { printf("Base::test_override_overload(int a)\n"); }; // overload 重载
};

class A : public Base
{
public:
    A() = default;
    ~A() = default;

public:
    int test_override() { printf("A::test_override()\n"); };
    int test_virtual_override() override { printf("A::test_virtual_override()\n"); };
};

int main(int argn, char **argv)
{
    printf("------------------------------------------\n");
    printf("### 直接调用 ###\n");
    A aa = A();
    aa.test_override();                   //A::test_override()
    // aa.test_override_overload(1);      //编译错误 ###
    aa.test_not_override();               //Base::test_override()
    aa.test_not_override_overload(1);     //Base::test_not_override_overload(int a)
    aa.test_virtual_override();           //A::test_virtual_override()
    aa.test_virtual_override_overload(1); //Base::test_override_overload(int a)
    printf("### 转为父类指针调用 ###\n");
    Base *base = &aa;
    base->test_override();                   //Base::test_override()
    base->test_override_overload(1);         //Base::test_override_overload(int a)
    base->test_not_override();               //Base::test_override()
    base->test_not_override_overload(1);     //Base::test_not_override_overload(int a)
    base->test_virtual_override();           //A::test_virtual_override() ###
    base->test_virtual_override_overload(1); //Base::test_override_overload(int a)
    printf("------------------------------------------\n");
    printf("父类的同名函数如果被重写，派生类对象不能调用父类的成员函数，需要转为父类指针才可调用\n");
    printf("virtual重写的派生类对象，即使转为父类指针调用也是调用子列重写的函数\n");
    printf("------------------------------------------\n");
    return 0;
}